package com.qqtop10.manager.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qqtop10.manager.model.PagingArgs;
import com.qqtop10.manager.model.Result;
import com.qqtop10.manager.model.Withdrawal;
import com.qqtop10.manager.service.WithdrawalService;
import com.sun.corba.se.spi.orbutil.fsm.Input;

@RequestMapping("/manager/withdrawal/")
@Controller
public class WithdrawalController extends BaseController {
	@Autowired
	private WithdrawalService withdrawalService;

	@RequestMapping("all.do")
	@ResponseBody
	public Result all(Withdrawal input) {
		try {
			input.setUsaccount(URLDecoder.decode(input.getUsaccount(), "UTF-8"));
			// input.setUsername(URLDecoder.decode(input.getUsername(),"UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		try {
			PagingArgs pagingArgs = getPagingArgs();
			int count = withdrawalService.count(input);
			List<Withdrawal> list = withdrawalService.all(input, pagingArgs);
			return page(count, list);
		} catch (Exception e) {
			return excep(e);
		}
	}

	@RequestMapping("updateById")
	@ResponseBody
	public Result updateById(Withdrawal input) {

		if ((input == null) || (input.getId() == null) || (input.getStatus() == null)) {
			return new Result(1, "有些必须的参数未指定。");
		}
		
		try {
			// 获取当前设置人id
			input.setAccount(getLogindUuid());
			input.setUpdated_at(now());
			if (withdrawalService.updateById(input)) {
				return ok("操作成功");
			}
			return err("请检查网络");
		} catch (Exception e) {
			return excep(e);
		}
	}
}
